/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.utils.pele;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 *
 * @author rudieri
 */
public class JSelecionaCor extends javax.swing.JDialog implements ActionListener {

    /**
     * Creates new form JPele
     */
    private ArrayList<CorSelecionadaListener> corSelecionadaListeners;

    public JSelecionaCor(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        corSelecionadaListeners = new ArrayList<CorSelecionadaListener>();
        startEvents();
    }

    public void addCorSelecionadaListener(CorSelecionadaListener corSelecionadaListener) {
        corSelecionadaListeners.add(corSelecionadaListener);
    }

    public boolean removeCorSelecionadaListener(CorSelecionadaListener corSelecionadaListener) {
        return corSelecionadaListeners.remove(corSelecionadaListener);
    }

    private void startEvents() {
        jButtonOK.addActionListener(this);
        jButtonCancelar.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jButtonOK) {
            dispose();
            for (int i = 0; i < corSelecionadaListeners.size(); i++) {
                corSelecionadaListeners.get(i).corSelecionada(jColorChooser1.getColor());
            }
        } else if (e.getSource() == jButtonCancelar) {
            dispose();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jColorChooser1 = new javax.swing.JColorChooser();
        jPanel1 = new javax.swing.JPanel();
        jButtonOK = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().add(jColorChooser1, java.awt.BorderLayout.CENTER);

        jButtonOK.setText("OK");
        jPanel1.add(jButtonOK);

        jButtonCancelar.setText("Cancelar");
        jPanel1.add(jButtonCancelar);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JColorChooser jColorChooser1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
